package com.wyhello.tube4.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.wyhello.tube4.dao.DrawRecordsDAO;
import com.wyhello.tube4.pojo.Draw;

public class DrawRecordsDAOImpl  implements DrawRecordsDAO{
	private SessionFactory sessionFactory;
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	/**
	 * 实际测量信息的录入
	 * @param draw 要录入的信息
	 * @return 返回是否录入成功
	 */
	@Override
	public boolean saveDraw(Draw draw) {
		Session session = sessionFactory.getCurrentSession();
		int i = 1;
		try{
			session.save(draw);
		}catch(Exception e){
			i=0;
		}
		if(i==1){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 对图纸信息进行批量删除
	 * @param ids 要删除的id
	 * @return 返回删除的条数
	 */
	@Override
	public int deleteDraw(String ids) {
		Session session  =  sessionFactory.getCurrentSession();
		String sql = "delete from draw where id in "+ids;
		int i = session.createSQLQuery(sql).executeUpdate();
		return i;
	}
	/**
	 * 查询所有的图纸信息
	 * @return 返回所有图纸信息
	 */
	@Override
	public List<Draw> queryDraw() {
		Session session  =  sessionFactory.getCurrentSession();
		String hql = "from Draw";
		List<Draw> list = session.createQuery(hql).list();
		return list;
	}
	/**
	 * 根据id查询图纸信息
	 * @param id 要查询的id
	 * @return 为ID的图纸
	 */
	@Override
	public Draw getDrawById(int id) {
		Session session  =  sessionFactory.getCurrentSession();
		Draw draw = (Draw) session.get(Draw.class, Integer.valueOf(id));
		return draw;
	}
}
